
import sys
import numpy
import matplotlib.pyplot as plt
# compare result of python program and that of matlab
# example:read in npy created by build_spec.py  and compare against the result by matlab

if len(sys.argv)<3:
    print('usage:')
    sys.exit(0)

npy = sys.argv[1]

# 98*50
txt = sys.argv[2]
py = numpy.load(npy)
print(py.shape)

matlab = numpy.loadtxt(txt)
print(matlab.shape)

diff = py-matlab
sqr = numpy.abs(diff )

#plt.figure(0)
#x = sqr.shape[0]
#y = sqr.shape[1]
#Y = numpy.arange(0, y / 100, 0.01)
#X = numpy.arange(0, x / 100, 0.01)
#c = plt.pcolormesh(X,Y,sqr.T, shading='nearest')
#plt.colorbar(c)
#plt.show()

plt.figure(1)
x = py.shape[0]
y = py.shape[1]
Y = numpy.arange(0, y / 100, 0.01)
X = numpy.arange(0, x / 100, 0.01)
c = plt.pcolormesh(X,Y,py.T, shading='nearest')
plt.colorbar(c)
#plt.show()

plt.figure(2)
x = matlab.shape[0]
y = matlab.shape[1]
Y = numpy.arange(0, y / 100, 0.01)
X = numpy.arange(0, x / 100, 0.01)
c = plt.pcolormesh(X,Y,matlab.T, shading='nearest')
plt.colorbar(c)
plt.show()
#row_max=sqr.argmax(axis=1)
#x = [sqr[i][row_max[i]] for i in range(len(row_max))]
#print("max index:")
#print(x)

tmp = sqr.reshape(1,-1)
sum = numpy.sum(tmp)
print("sum:%f"%sum)
max = numpy.max(tmp)

total=numpy.sum(numpy.where(tmp==0,1,0))
print("max:%f"%max)
max = numpy.max(py)
print("max1:%f"%max)
max = numpy.max(matlab)
print("max2:%f"%max)

print("total eq  :%d"%total)
total= len(tmp[0])-total
print("total neq  :%d"%total)


